import requests,time
from bs4 import BeautifulSoup
import urllib.request
url = 'https://weheartit.com/inspirations/taylorswift?scrolling=true&page=2&before=309342080'
headers = {
    'Cookie' : 'showed_entry_ftue=1; locale=zh-cn; __whiAnonymousID=7973296036b8460d82c29f7a241c5289; auth=no; _whisession=5d146646fbe2d8859edaf192576708b5; _ga=GA1.2.2081569764.1524385460; _gid=GA1.2.312295771.1524385460; __qca=P0-551042510-1524385524752; __gads=ID=df89dbd8d4790a3d:T=1524389863:S=ALNI_MZuLrehuvi14QSgmh00XY-QK5FJ2Q; _weheartit_anonymous_session=%7B%22page_views%22%3A2%2C%22search_count%22%3A0%2C%22last_searches%22%3A%5B%5D%2C%22last_page_view_at%22%3A1524391415068%7D',
    'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
}
def get_page(url,data=None):
    web_data = requests.get(url,headers=headers)
    soup = BeautifulSoup(web_data.text,'lxml')
    imgs = soup.select('div.entry-preview > a > img')
    if data == None:
        for i in imgs:
            print(i.get('src'))

def get_more_page(start,end):
    for one in range(start,end):
        get_page(url+str(one))

def wirte_local():
    imgs_list = get_more_page(1,20)
    dir = "D:\python3.6爬虫\week_one\phone"
    x = 0
    for i in imgs_list:
        urllib.request.urlretrieve(i, '{}{}.jpg'.format(dir, x))
        x = x+1


wirte_local()